﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Newtonsoft.Json.Linq;

namespace Sina.Altman.Weibo.SDK.Objects
{
    /// <summary>
    /// 所有评论的集合,并包含指向上下的指针
    /// </summary>
    public class Comments
    {
        public Comments(string json)
            : this(JObject.Parse(json))
        {
        }

        private JObject __jobject;
        public Comments(JObject obj)
        {
            this.__jobject = obj;
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Comment[] _commentItems;
        public Comment[] CommentItems
        {
            get
            {
                if (_commentItems == null)
                    _commentItems = (Comment[])JsonClassHelper.ReadArray<Comment>(JsonClassHelper.GetJToken<JArray>(__jobject, "comments"), JsonClassHelper.ReadStronglyTypedObject<Comment>, typeof(Comment[]));
                return _commentItems;
            }
        }

        public int PreviousCursor
        {
            get
            {
                return JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "previous_cursor"));
            }
        }

        public int NextCursor
        {
            get
            {
                return JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "next_cursor"));
            }
        }

        public int TotalNumber
        {
            get
            {
                return JsonClassHelper.ReadInteger(JsonClassHelper.GetJToken<JValue>(__jobject, "total_number"));
            }
        }
    }

    /// <summary>
    /// 单条评论
    /// </summary>
    public class Comment
    {
        public Comment(string json):this(JObject.Parse(json))
        {

        }

        private JObject __jobject;
        public Comment(JObject obj)
        {
            this.__jobject = obj;
        }

        public string CreatedAt
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "created_at"));
            }
        }

        public long Id
        {
            get
            {
                return JsonClassHelper.ReadLong(JsonClassHelper.GetJToken<JValue>(__jobject, "id"));
            }
        }

        public string Text
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "text"));
            }
        }

        public string Source
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "source"));
            }
        }

        public string Mid
        {
            get
            {
                return JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "mid"));
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private User _user;
        public User User
        {
            get
            {
                if (_user == null)
                    _user = JsonClassHelper.ReadStronglyTypedObject<User>(JsonClassHelper.GetJToken<JObject>(__jobject, "user"));
                return _user;
            }
        }

        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private Status2 _status;
        public Status2 Status
        {
            get
            {
                if (_status == null)
                    _status = JsonClassHelper.ReadStronglyTypedObject<Status2>(JsonClassHelper.GetJToken<JObject>(__jobject, "status"));
                return _status;
            }
        }
    }
}
